function [midres,hideres] = question2()
% QUESTION2 - P107第二题
%   输出变量：
%   midres  ：中心差商的误差数组
%   hideres ：隐式方法的误差数组
    n =  10;
    h = 1/n;
    x = 0:h:1;
    f = fun(x);
    precise = diffun(x);
    for i =2:n;
        mid(i-1) = (f(i+1)-f(i-1))/(2*h);
    end
    midres = mid - precise(2:n);
    A = 4*eye(n-1);
    
    for i =1:n-2
        A(i,i+1) = 1;
        A(i+1,i) = 1;
    end
    
    b = zeros(9,1);
    
    for i = 2:n,
        b(i-1) = 3*(f(i+1)-f(i-1))/h;
    end
    b(1)=b(1)-precise(1);
    b(n-1)=b(n-1)-precise(n+1);
    hide = A\b;
    hide = hide';
    hideres = hide -precise(2:n) ;   
    
end

function y = fun(x)
% FUN - f(x)=exp(-x/4)
%   
    y = exp(-x/4);
end

function y = diffun(x)
% DIFFUN - 导数的精确值
%   
    y = -exp(-x/4)/4;
end

